﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Samples.ServiceHosting.StorageClient;
using UlyssesAgenda.Repositories.GameObjects;
using UlyssesAgenda.Repositories.Regions;
using UlyssesAgenda.Repositories.Blog;

namespace UlyssesAgenda.Repositories
{
    public static class RepositoryFactory
    {
        private static StorageAccountInfo blobAccount;
        private static StorageAccountInfo tableAccount;
        private static StorageAccountInfo queueAccount;

        public static T GetRepository<T>() where T:CloudStorageRepositoryBase
        {
            if (blobAccount == null)
                blobAccount = StorageAccountInfo.GetDefaultBlobStorageAccountFromConfiguration();
            if (tableAccount == null)
                tableAccount = StorageAccountInfo.GetDefaultTableStorageAccountFromConfiguration();
            if (queueAccount == null)
                queueAccount = StorageAccountInfo.GetDefaultQueueStorageAccountFromConfiguration();

            T repository = null;
            if (typeof(T).ToString() == "UlyssesAgenda.Repositories.GameObjects.GameObjectRepository")
            {
                GameObjectRepository repo = new GameObjectRepository(blobAccount, queueAccount, tableAccount);
                repository = repo as T;
            }
            else if (typeof(T).ToString() == "UlyssesAgenda.Repositories.Regions.RegionRepository")
            {
                RegionRepository repo = new RegionRepository(blobAccount, queueAccount, tableAccount);
                repository = repo as T;
            }
            else if (typeof(T).ToString() == "UlyssesAgenda.Repositories.Blog.BlogEntryRepository")
            {
                BlogEntryRepository repo = new BlogEntryRepository(blobAccount, queueAccount, tableAccount);
                repository = repo as T;
            }

            return repository;
        }
    }
}
